package lesson4;

import java.io.File;

public class Demo1 {
    public static void main(String[] args) {
        //listAllFiles("C:\\Users\\Administrator\\Desktop\\TestFile2");
        //listAllFiles("C:/");
//        File file = new File("C:\\Program Files\\" +
//                "WindowsApps\\Microsoft.WindowsCamera_2020.902.20.0_x64__8wekyb3d8bbwe\\" +
//                "Assets\\contrast-black");
//        File file = new File("C:\\Users\\Administrator\\Desktop\\1111");
//        if(file.isDirectory()){
//            System.out.println("文件夹");
//            File[] files = file.listFiles();
//            System.out.println("---------------");
//        }

        listAllFiles("d:/",".java");
    }

    //
    public static void listAllFiles(String dirPath){
        File dirFile = new File(dirPath);
        if(!dirFile.isDirectory()){
            return;
        }
        File[] files = dirFile.listFiles();
        if(files == null){
            return;
        }
        for(File file:files){
            System.out.println(file.getAbsolutePath());
            if(file.isDirectory()){
                listAllFiles(file.getAbsolutePath());
            }
        }
    }


    public static void listAllFiles(String dirPath,String fileType){
        File dirFile = new File(dirPath);
        if(!dirFile.isDirectory()){
            return;
        }
        File[] files = dirFile.listFiles();
        if(files == null){
            return;
        }
        for(File file:files){
            //System.out.println(file.getAbsolutePath());
            if(file.isFile() && file.getName().endsWith(fileType)){
                System.out.println(file.getAbsolutePath());
            }
            if(file.isDirectory()){
                listAllFiles(file.getAbsolutePath(),fileType);
            }
        }
    }
}
